home *** CD-ROM | disk | FTP | other *** search
/ HAKERIS 11 / HAKERIS 11.ISO / soft / development / Macromedia RoboHelp X5 / RoboHelpOffice.exe / Data1.cab / _68BC30C02E974B65B32C057EE8EA4F25 < prev    next >
Encoding:
Text File  |  2003-03-20  |  21.6 KB  |  679 lines

  1. /***************************************************************************************** 
  2.    Context-Sensitive-Help API for WebHelp Enterprise, RoboInfo and WebHelp
  3.    eHelp« Corporation
  4.    Copyright⌐ 1998-2001 eHelp« Corporation.All rights reserved.
  5. *****************************************************************************************/
  6.  
  7. // if you are using VC++, please go to menu Project|Settings..., 
  8. // set RoboHelp_CSH.cpp not using precompiled headers.
  9. // Otherwize you will get compiling: c1010: unexpected eof while looking for precompiled header directive.
  10.  
  11. /* Example function calls
  12. // First, create RH_WindowOption object
  13. RH_WindowOption MyWin;
  14. // Set window style and position in object
  15. MyWin.m_nStyle = RHWO_LOCATION | RHWO_MENUBAR | RHWO_RESIZABLE;
  16. MyWin.m_nTop = 50;
  17. MyWin.m_nLeft=50;
  18. MyWin.m_nHeight=300;
  19. MyWin.m_nWidth=400;
  20.  
  21. // Show Help for topic with HTML Help Map number 11:
  22. RH_ShowHelpById("c:\\myapp\\help\\start_rhc.htm", "11", "myHelpWindow", MyWin);
  23.  
  24. // Show Help for topic with Context String ID "My_Topic"
  25. RH_ShowHelpByString("c:\\myapp\\help\\start_rhc.htm"", "My_Topic", "myHelpWindow", MyWin);
  26. */
  27.  
  28. #include <process.h>
  29. #include <stdlib.h>
  30. #include <stdio.h>
  31.  
  32. #ifdef _WIN32                //Win32 platform
  33. #include <windows.h>
  34. #include <shellapi.h>
  35. #include <MSHTML.H>            // IE Interfaces.
  36. #include <Exdisp.h>
  37. #else                        //non-Win32 platform, probably Unix. here we include a header file for unix.
  38. #include <unistd.h>
  39. #endif
  40.  
  41.  
  42. #include "RoboHelp_Csh.h"
  43.  
  44. #pragma warning( disable : 4702 )
  45.  
  46. /* constant */
  47. #define DEFAULT_RH_TARGET_ID ""
  48. #define AUTOCONTEXTID_PREFIX "HelpIdFromHTMLHelp"   // the prefix used to auto translate from topic number to context id
  49. /* static local variable*/
  50. static char s_szBrowserName[MAX_PATH] = "netscape";
  51. static int gbCoInited=0;
  52.  
  53. //////////////////////////////////////////////////////////////////////////////
  54. #ifdef _WIN32
  55.  
  56. GUID RH_IID_ITargetFrame2 =      {0x86D52E11,  0x94A8, 0x11d0, {0x82,0xAF,0x00,0xC0,0x4F,0xD5,0xAE,0x38}};
  57.  
  58. interface ITargetFrame2 : public IUnknown
  59. {
  60. public:
  61.     virtual HRESULT STDMETHODCALLTYPE SetFrameName( 
  62.         /* [in] */ LPCWSTR pszFrameName) = 0;
  63.     
  64.     virtual HRESULT STDMETHODCALLTYPE GetFrameName( 
  65.         /* [out] */ LPWSTR __RPC_FAR *ppszFrameName) = 0;
  66.     
  67.     virtual HRESULT STDMETHODCALLTYPE GetParentFrame( 
  68.         /* [out] */ IUnknown __RPC_FAR *__RPC_FAR *ppunkParent) = 0;
  69.     
  70.     virtual HRESULT STDMETHODCALLTYPE SetFrameSrc( 
  71.         /* [in] */ LPCWSTR pszFrameSrc) = 0;
  72.     
  73.     virtual HRESULT STDMETHODCALLTYPE GetFrameSrc( 
  74.         /* [out] */ LPWSTR __RPC_FAR *ppszFrameSrc) = 0;
  75.     
  76.     virtual HRESULT STDMETHODCALLTYPE GetFramesContainer( 
  77.         /* [out] */ IOleContainer __RPC_FAR *__RPC_FAR *ppContainer) = 0;
  78.     
  79.     virtual HRESULT STDMETHODCALLTYPE SetFrameOptions( 
  80.         /* [in] */ DWORD dwFlags) = 0;
  81.     
  82.     virtual HRESULT STDMETHODCALLTYPE GetFrameOptions( 
  83.         /* [out] */ DWORD __RPC_FAR *pdwFlags) = 0;
  84.     
  85.     virtual HRESULT STDMETHODCALLTYPE SetFrameMargins( 
  86.         /* [in] */ DWORD dwWidth,
  87.         /* [in] */ DWORD dwHeight) = 0;
  88.     
  89.     virtual HRESULT STDMETHODCALLTYPE GetFrameMargins( 
  90.         /* [out] */ DWORD __RPC_FAR *pdwWidth,
  91.         /* [out] */ DWORD __RPC_FAR *pdwHeight) = 0;
  92.     
  93.     virtual HRESULT STDMETHODCALLTYPE FindFrame( 
  94.         /* [unique][in] */ LPCWSTR pszTargetName,
  95.         /* [in] */ DWORD dwFlags,
  96.         /* [out] */ IUnknown __RPC_FAR *__RPC_FAR *ppunkTargetFrame) = 0;
  97.     
  98.     virtual HRESULT STDMETHODCALLTYPE GetTargetAlias( 
  99.         /* [unique][in] */ LPCWSTR pszTargetName,
  100.         /* [out] */ LPWSTR __RPC_FAR *ppszTargetAlias) = 0;
  101.     
  102. };
  103.  
  104.  
  105. IWebBrowser2* GetBrowser() 
  106. {
  107.     IWebBrowser2 *pBrowser = NULL;
  108.     // If the caller already initialize COM, please comment out the next 5 lines.
  109.     if (!gbCoInited)
  110.     {
  111.         ::CoInitialize(NULL);
  112.         gbCoInited=1;
  113.     }
  114.     CoCreateInstance(CLSID_InternetExplorer, NULL, CLSCTX_LOCAL_SERVER,IID_IWebBrowser2,  (LPVOID FAR*)&pBrowser); 
  115.     return pBrowser;
  116. };
  117.  
  118. #endif
  119.  
  120. /* local static routines */
  121. static int IsServerBased(const char *a_pszUrlToHelpSet);
  122. static int MakeUrlForServerBased(const char *a_pszUrlToHelpSet, const char *a_pszContextID, char *a_pszResult);
  123. static int MakeUrlForWebHelpBased(const char *a_pszUrlToHelpSet, const char *a_pszContextID, char *a_pszResult);
  124.  
  125. static int ShowHelpTopic_Win32(const char *a_pszUrl,RH_WindowOption *a_pWndOption, const char *a_pszTargetID);
  126. static int ShowHelpTopic_NonWin32(const char *a_pszUrl,RH_WindowOption *a_pWndOption, const char *a_pszTargetID);
  127.  
  128. #ifdef _WIN32
  129. static int ShowHelpTopic_Win32_IE(const char *a_pszUrl,RH_WindowOption *a_pWndOption, const char *a_pszTargetID);
  130. static int ShowHelpTopic_Win32_NonIE(const char *a_pszUrl,RH_WindowOption *a_pWndOption);
  131. #endif
  132.  
  133. /**********************************************
  134.  Show Help topic by topic number generated for HtmlHelp.
  135.  Parameters:
  136.   [in] a_pszUrlToHelpSet:  url to helpset. for WebHelp Enterprise it is the url to server name, such as "http://helpserver.com/RoboApi.asp"
  137.                            for webhelp, it is full path name the webhelp start page name, such as "c:\myapp\help\start_rhc.htm" or "/user/myapp/help/start_rhc.htm"
  138.   [in] a_nTopicNumber:     topic number generated for the HTMLHelp context sensitive help.
  139.   [in] a_pszTargetID:      browser's target name, such as "mynewtopic"
  140.   [in] a_pcWindowOption:   browser options. can be 0.
  141.  Result:
  142.    0:      successful
  143.   non-0:  error code.
  144. **********************************************/
  145.  
  146. int  RH_ShowHelpById(const char * a_pszUrlToHelpSet,
  147.                  unsigned long a_nTopicNumber,
  148.                  const char * a_pszTargetID,
  149.                  RH_WindowOption * a_pcWindowOption)
  150. {
  151.     char szAutoContextID[MAX_PATH];
  152.     sprintf(szAutoContextID, "%s_%d", AUTOCONTEXTID_PREFIX, a_nTopicNumber);
  153.     return RH_ShowHelpByString(a_pszUrlToHelpSet, szAutoContextID, a_pszTargetID, a_pcWindowOption);
  154. }
  155.  
  156. /******************************************************************************************************************************************
  157.  Show Help topic
  158.  Parameters:
  159.   [in] a_pszUrlToHelpSet:  url to helpset. for WebHelp Enterprise it is the url to server name, such as "http://helpserver.com/RoboApi.asp"
  160.                            for webhelp, it is full path name the webhelp start page name, such as "c:\myapp\help\start_rhc.htm" or "/user/myapp/help/start_rhc.htm"
  161.   [in] a_pszContextID:     context id of the topic
  162.   [in] a_pszTargetID:      browser's target name, such as reserved "_top","_parent" or custmized "myhelpwindow"
  163.   [in] a_pcWindowOption:   browser options. can be 0.
  164.  Result:
  165.    0:      successful
  166.   non-0:  error code.
  167. ******************************************************************************************************************************************/
  168.  
  169. int  RH_ShowHelpByString(const char * a_pszUrlToHelpSet,
  170.                  const char * a_pszContextID,
  171.                  const char * a_pszTargetID,
  172.                  RH_WindowOption * a_pcWindowOption)
  173. {
  174.     char szUrl[MAX_RH_URL_BUFLEN];
  175.     char szContextID[MAX_RH_URL_BUFLEN];
  176.     char szTarget[256];
  177.     RH_WindowOption cOpt;
  178.     int  nMake;
  179.  
  180.     if (a_pszUrlToHelpSet == NULL)
  181.         return -1;
  182.  
  183.     //init
  184.     szUrl[0] = 0x00;
  185.     szContextID[0] = 0x00;
  186.     memset(&cOpt,0,sizeof(RH_WindowOption));
  187.     strncpy(szTarget,DEFAULT_RH_TARGET_ID,255);
  188.  
  189.     //Make safe default value of context id and windowoption
  190.     if (a_pszContextID != 0)
  191.         strncpy(szContextID,a_pszContextID,MAX_RH_URL_BUFLEN);
  192.     if (a_pcWindowOption != 0)
  193.     {
  194.         memcpy(&cOpt,a_pcWindowOption,sizeof(RH_WindowOption));
  195.     }
  196.     else
  197.     {
  198.         cOpt.m_nStyle = 0;
  199.         cOpt.m_nTop = 10;
  200.         cOpt.m_nLeft = 10;
  201.         cOpt.m_nHeight = 300;
  202.         cOpt.m_nWidth  = 400;
  203.     }
  204.  
  205.     //can different agent to make url.
  206.     if (IsServerBased(a_pszUrlToHelpSet))
  207.     {
  208.         nMake = MakeUrlForServerBased(a_pszUrlToHelpSet,szContextID,szUrl);
  209.     }
  210.     else
  211.     {
  212.         nMake = MakeUrlForWebHelpBased(a_pszUrlToHelpSet,szContextID,szUrl);
  213.     }
  214.  
  215.     //bring up the topic now.
  216.     if (nMake == 0)
  217.     {
  218.         if (a_pszTargetID != 0)
  219.             strcpy(szTarget,a_pszTargetID);
  220. #ifdef _WIN32                
  221.         return ShowHelpTopic_Win32(szUrl,&cOpt,szTarget);
  222. #else
  223.         return ShowHelpTopic_NonWin32(szUrl,&cOpt,szTarget);
  224. #endif
  225.     }
  226.     return -1;
  227. }
  228.  
  229.  
  230.  
  231. /******************************************************************************************************************************************
  232.   close browser with specific target name 
  233.   Parameter:
  234.    [in] a_pszTargetID:      browser's target name, such as reserved "_top","_parent" or custmized "myhelpwindow"
  235.   Result:
  236.    0:      successful
  237.    non-0:  error code.
  238. *******************************************************************************************************************************************/
  239. int    RH_CloseHelpTarget(const char * a_pszTargetID)
  240. {
  241. #ifdef _WIN32
  242.     //go to the page
  243.     IWebBrowser2 *pBrowser = GetBrowser();
  244.     if (pBrowser != NULL)
  245.     {
  246.         ITargetFrame2 *pTargetFrame2 = NULL;
  247.         pBrowser->QueryInterface(RH_IID_ITargetFrame2, (void**) &pTargetFrame2);
  248.         if (pTargetFrame2 != NULL)
  249.         {
  250.             BSTR bstrTarget;
  251.             bstrTarget = ::SysAllocStringLen(NULL, strlen(a_pszTargetID));
  252.             MultiByteToWideChar(CP_ACP, MB_USEGLYPHCHARS, a_pszTargetID, strlen(a_pszTargetID), bstrTarget,strlen(a_pszTargetID));
  253.  
  254.             IWebBrowser2 *pBrowser = NULL;
  255.  
  256.             //IE 5.0+
  257.             IUnknown *pUnk = NULL;
  258.             pTargetFrame2->FindFrame(bstrTarget,0,&pUnk);
  259.             if (pUnk != NULL)
  260.             {
  261.                 pUnk->QueryInterface(IID_IWebBrowser2,(void **)&pBrowser);
  262.                 if (pBrowser != NULL)
  263.                 {
  264.                     //It is easy to make the brower invisble, 
  265.                     //otherwise there possilble two ways to close the browser:
  266.                     //1: Get hWnd of the browser and sent WM_QUIT to the host frame of this window
  267.                     //2: Get Container (OleContainer) and ask container close itself
  268.                     pBrowser->Quit();
  269.                     pBrowser->Release();
  270.                 }
  271.                 pUnk->Release();
  272.             }
  273.             pTargetFrame2->Release();
  274.         }
  275.         pBrowser->Quit();
  276.         pBrowser->Release();
  277.     }
  278. #endif
  279.     return 0;
  280. }
  281.  
  282.  
  283. /******************************************************************************************************************************************
  284.  Query the url to help topic by context id
  285.  Parameters:
  286.   [in] a_pszUrlToHelpSet:  url to helpset. for WebHelp Enterprise it is the url to server name, such as "http://helpserver.com/RoboApi.asp"
  287.                            for webhelp, it is full path name the webhelp start page name, such as "c:\myapp\help\start_rhc.htm" or "/user/myapp/help/start_rhc.htm"
  288.   [in] a_pszContextID:     context id of the topic
  289.   [out]a_pszRetUrlBuf:     a buffer to receive the finial result url, it's lenght need at least MAX_RET_URL_BUFLEN (2048).
  290.  
  291.  Result Code:
  292.    0:      successful
  293.   non-0:  error code.
  294.  
  295. ******************************************************************************************************************************************/
  296. int  RH_MakeTopicURL(const char * a_pszUrlToHelpSet,
  297.                      const char * a_pszContextID,
  298.                      char *a_pszRetUrlBuf)
  299. {
  300.     if (IsServerBased(a_pszUrlToHelpSet))
  301.         return MakeUrlForServerBased(a_pszUrlToHelpSet,a_pszContextID,a_pszRetUrlBuf);
  302.     return MakeUrlForWebHelpBased(a_pszUrlToHelpSet,a_pszContextID,a_pszRetUrlBuf);
  303. }
  304.  
  305.  
  306. /**********************************************
  307.  Query the url to help topic by context id
  308.  Parameters:
  309.   [in] a_pszBroserName    default broser name such as "netscape" "iexplorer" 
  310.  
  311.  Result Code:
  312.    0:      successful
  313.   non-0:  error code.
  314.  
  315. **********************************************/
  316. int  RH_SetDefaultBrowser(const char * a_pszBrowserName)
  317. {
  318.     strncpy(s_szBrowserName,a_pszBrowserName,MAX_PATH);
  319.     return 0;
  320. }
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327. /**********************************************************************************************************
  328. *************************************** Internal routines *************************************************
  329. ***********************************************************************************************************/
  330.  
  331. /* Is Server based or not (WebHelp Enterprise/RHI or WebHelp) */
  332. int IsServerBased(const char *a_pszUrlToHelpSet)
  333. {
  334.     char *pDot = strrchr(a_pszUrlToHelpSet,'.');
  335.     if ((pDot != 0) &&
  336.         ((a_pszUrlToHelpSet + strlen(a_pszUrlToHelpSet) - pDot) == 4) &&
  337.         (stricmp(pDot,".asp") == 0))
  338.     {
  339.         return 1;
  340.     }
  341.     return 0;
  342. }
  343.  
  344. /* Make URL for WebHelp Enterprise/RHI */
  345. int MakeUrlForServerBased(const char *a_pszUrlToHelpSet, const char *a_pszContextID, char *a_pszResult)
  346. {
  347.     if (a_pszResult != 0)
  348.     {
  349.         sprintf(a_pszResult,"%s?context=%s",a_pszUrlToHelpSet,a_pszContextID);
  350.         return 0;
  351.     }
  352.     return -1;
  353. }
  354.  
  355. /* Make URL for WebHelp */
  356. int MakeUrlForWebHelpBased(const char *a_pszUrlToHelpSet, const char *a_pszContextID, char *a_pszResult)
  357. {
  358.     if (a_pszResult != 0)
  359.     {
  360.         //expact "start_rhc.htm" as start page for csh for "start.htm" project
  361.         char szPath[MAX_RH_URL_BUFLEN];
  362.         strncpy(szPath,a_pszUrlToHelpSet,MAX_RH_URL_BUFLEN);
  363.         
  364.         char szExt[6]; szExt[0] = 0x00;
  365.  
  366. /*        char *pDot = strrchr(szPath,'.');
  367.         int nLen = strlen(szPath);
  368.         char *pEnd = szPath + nLen;
  369.         if ((pDot != 0) &&
  370.             (((pEnd - pDot) == 4) || ((pEnd - pDot) == 5)))
  371.         {
  372.             strcpy(szExt,pDot);
  373.             strcpy(pDot,"_rhc");
  374.             strcat(pDot,szExt);*/
  375.  
  376.             sprintf(a_pszResult,"%s#context=%s",szPath,a_pszContextID);
  377.             return 0;
  378. //        }
  379.     }
  380.     return -1;
  381. }
  382.  
  383. /* Show Help topic in non-Win32 platform */
  384. int ShowHelpTopic_NonWin32(const char *a_pszUrl)
  385. {
  386.     /*for non-window 32 system, we call the browser directly.
  387.      because it is impossible to dectect which browser is installed in non-win32 platform. so we have to hardcode the broser name to "netscape".
  388.      for those, who have different browser, please update the browser name here.
  389.     */
  390.     return (execl(s_szBrowserName, a_pszUrl, 0) == -1)? -1: 0;
  391. }
  392.  
  393. /* Show Help topic in Win32 platform */
  394. int ShowHelpTopic_Win32(const char *a_pszUrl,RH_WindowOption *a_pWndOption, const char *a_pszTargetID)
  395. {
  396.     int nRet=0;
  397. #ifdef _WIN32
  398.     IWebBrowser2 *pBrowser = GetBrowser();
  399.     if (pBrowser!= NULL)
  400.     {
  401.         nRet=ShowHelpTopic_Win32_IE(a_pszUrl,a_pWndOption,a_pszTargetID);
  402.         pBrowser->Quit();
  403.         pBrowser->Release();
  404.     }
  405.     else
  406.         nRet=ShowHelpTopic_Win32_NonIE(a_pszUrl,a_pWndOption);
  407.  
  408. #endif
  409.     return nRet;
  410. }
  411.  
  412. #ifdef _WIN32
  413. static int ShowHelpTopic_Win32_IE(const char *a_pszUrl,RH_WindowOption *a_pWndOption, const char *a_pszTargetID)
  414. {
  415.     HRESULT hr = 0;
  416.     BSTR bstrTarget;
  417.     bstrTarget = ::SysAllocStringLen(NULL, strlen(a_pszTargetID));
  418.     MultiByteToWideChar(CP_ACP, MB_USEGLYPHCHARS, a_pszTargetID, strlen(a_pszTargetID), bstrTarget,strlen(a_pszTargetID));
  419.  
  420.     IWebBrowser2 *pBrowser = GetBrowser();
  421.     if (!pBrowser) return 0;
  422.  
  423.     int len = strlen(a_pszUrl);
  424.     BSTR bstr;
  425.     bstr = ::SysAllocStringLen(NULL, len);
  426.     MultiByteToWideChar(CP_ACP, MB_USEGLYPHCHARS, a_pszUrl, strlen(a_pszUrl), bstr, len);
  427.  
  428.     VARIANT vFlags = {0};
  429.     V_VT(&vFlags) = VT_I4;
  430.     V_I4(&vFlags) = 0;
  431.  
  432.     VARIANT vPostData = {0};
  433.     VARIANT vTargetFrameName = {0};
  434.  
  435.     // Put data into safe array.
  436.     LPSAFEARRAY psa = SafeArrayCreateVector(VT_UI1, 0, 0);
  437.  
  438.     LPSTR pPostData;
  439.     hr=SafeArrayAccessData(psa, (LPVOID*)&pPostData);
  440.     hr = SafeArrayUnaccessData(psa);
  441.  
  442.     // Package the SafeArray into a VARIANT.
  443.     V_VT(&vPostData) = VT_ARRAY | VT_UI1;
  444.     V_ARRAY(&vPostData) = psa;         
  445.     
  446.     // Get Headers.
  447.     VARIANT vHeaders = {0};
  448.     V_VT(&vHeaders) = VT_BSTR;         
  449.  
  450.     // Specify a binary Content-Type.
  451.     V_BSTR(&vHeaders) = SysAllocString(
  452.         L"Content-Type: application/octet-stream\r\n"
  453.         L"Content-Encoding: html/text\r\n");
  454.  
  455.     //target name
  456.     V_VT(&vTargetFrameName) = VT_BSTR;
  457.     V_BSTR(&vTargetFrameName) = SysAllocString(bstrTarget); // want to set framename? use ITargetFrame2 first. otherwise a new browser will open.
  458.  
  459.     ITargetFrame2 *pTargetFrame2= NULL;
  460.     pBrowser->QueryInterface(RH_IID_ITargetFrame2, (void**)&pTargetFrame2);
  461.     if (pTargetFrame2 != NULL)
  462.     {
  463.         if (strlen(a_pszTargetID) > 0)
  464.         {
  465.             //IE 5.0+
  466.             IUnknown *pUnk = NULL;
  467.             pTargetFrame2->FindFrame(bstrTarget,0,&pUnk);
  468.             if (pUnk != NULL)
  469.             {
  470.                 IWebBrowser2 *pBrowser2 = NULL;
  471.                 pUnk->QueryInterface(IID_IWebBrowser2,(void **)&pBrowser2);
  472.                 if (pBrowser2 != NULL)
  473.                 {
  474.                     pBrowser->Quit();
  475.                     pBrowser->Release();
  476.                     pBrowser = pBrowser2;
  477.                 }
  478.                 pUnk->Release();
  479.             }
  480.             else
  481.             {
  482.                 hr=pTargetFrame2->SetFrameName(bstrTarget);
  483.                 if (!SUCCEEDED(hr))
  484.                 {
  485.                     pBrowser->Quit();
  486.                     pBrowser->Release();
  487.                     return 0;
  488.                 }
  489.             }
  490.         }
  491.         pTargetFrame2->Release();
  492.     }
  493.     hr=pBrowser->Navigate(bstr, &vFlags, &vTargetFrameName, &vPostData, &vHeaders); 
  494.     //apply the style and size
  495.     hr=pBrowser->put_ToolBar((short)((a_pWndOption->m_nStyle & RHWO_TOOLBAR)? 1: 0));
  496.     hr=pBrowser->put_AddressBar((short)((a_pWndOption->m_nStyle & RHWO_LOCATION)? 1: 0));
  497.     hr=pBrowser->put_MenuBar((short)((a_pWndOption->m_nStyle & RHWO_MENUBAR)? 1: 0));
  498.     hr=pBrowser->put_Resizable((short)((a_pWndOption->m_nStyle & RHWO_RESIZABLE)? 1: 0));
  499.     hr=pBrowser->put_StatusBar((short)((a_pWndOption->m_nStyle & RHWO_STATUS)? 1: 0));
  500.  
  501.  
  502.     if (a_pWndOption->m_nTop >= 0)
  503.         hr=pBrowser->put_Top(a_pWndOption->m_nTop);
  504.     if (a_pWndOption->m_nWidth > 0)
  505.         hr=pBrowser->put_Width(a_pWndOption->m_nWidth);
  506.     if (a_pWndOption->m_nHeight > 0)
  507.         hr=pBrowser->put_Height(a_pWndOption->m_nHeight);
  508.     if (a_pWndOption->m_nLeft >= 0)
  509.         hr=pBrowser->put_Left(a_pWndOption->m_nLeft);
  510.  
  511.     IDispatch *pDocumentDispatch = NULL;
  512.     pBrowser->get_Document(&pDocumentDispatch);
  513.     if (pDocumentDispatch!=NULL)
  514.     {
  515.         IHTMLDocument2 *pDocument=NULL;
  516.         pDocumentDispatch->QueryInterface(IID_IHTMLDocument2, (void**)&pDocument);
  517.         if (pDocument!=NULL)
  518.         {
  519.             IHTMLElement *pBody=NULL;
  520.             pDocument->get_body(&pBody);
  521.             if (pBody!=NULL)
  522.             {
  523.                 BSTR bstrscroll;
  524.                 char szScroll[]="scroll";
  525.                 int nScrollLen=strlen(szScroll);
  526.                 bstrscroll = ::SysAllocStringLen(NULL, nScrollLen);
  527.                 MultiByteToWideChar(CP_ACP, MB_USEGLYPHCHARS, szScroll, nScrollLen, bstrscroll, nScrollLen);
  528.  
  529.                 VARIANT vValue = {0};
  530.                 V_VT(&vValue) = VT_BSTR;         
  531.                 if (a_pWndOption->m_nStyle & RHWO_SCROLLBARS)
  532.                     V_BSTR(&vValue) = SysAllocString(L"yes");
  533.                 else
  534.                     V_BSTR(&vValue) = SysAllocString(L"no");
  535.  
  536.                 pBody->setAttribute(bstrscroll,vValue, 0);
  537.                 pBody->Release();
  538.             }
  539.             pDocument->Release();
  540.         }
  541.         pDocumentDispatch->Release();
  542.     }
  543.  
  544.     //make it visiable
  545.     HWND hWnd;
  546.     hr=pBrowser->get_HWND((long*)&hWnd);
  547.     if (SUCCEEDED(hr))
  548.     {
  549.         ::SetWindowPos(hWnd,HWND_TOP,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE);
  550.     }
  551.     hr=pBrowser->put_Visible(TRUE);
  552.  
  553.     pBrowser->Release();
  554.     return 1;
  555. }
  556.  
  557. static int ShowHelpTopic_Win32_NonIE(const char *a_pszUrl,RH_WindowOption *a_pWndOption)
  558. {
  559.     //create a temp html file which will redirect it self to desired url
  560.     char szPath[MAX_PATH + 1];
  561.     char szFile[MAX_PATH + 1];
  562.     char szTopicParam[_MAX_PATH];
  563.     char strTop[20], strScreenY[20], strLeft[20], strScreenX[20], strHeight[20], strWidth[20], strOuterHeight[20], strOuterWidth[20];
  564.  
  565.     GetTempPath(MAX_PATH, szPath);
  566.     strcpy(szFile, szPath);
  567.     strcat(szFile, "robohelp_csh.htm");
  568.     OFSTRUCT of;
  569.     HFILE hFile = OpenFile(szFile, &of, OF_WRITE|OF_CREATE);
  570.     char szTempFileFormat[] = "<html>\r\n"
  571.             "<script language=\"Javascript\">\r\n"
  572.             "<!--\r\n"
  573.             "document.location=\"file://%s\";\r\n"
  574.             "//-->\r\n"
  575.             "</script>\r\n"
  576.             "</html>";
  577.  
  578.     szTopicParam[0] = '\0';
  579.     char *pPos = strchr(a_pszUrl, '\\');
  580.     while (pPos != NULL)
  581.     {
  582.         pPos[0] = '/';
  583.         pPos = strchr(pPos, '\\');
  584.     }
  585.     if (a_pWndOption->m_nStyle & RHWO_LOCATION) {
  586.         strcat(szTopicParam, ",location=yes");
  587.     }
  588.     else {
  589.         strcat(szTopicParam, ",location=no");
  590.     }
  591.  
  592.     if (a_pWndOption->m_nStyle & RHWO_MENUBAR) {
  593.         strcat(szTopicParam, ",menubar=yes");
  594.     }
  595.     else {
  596.         strcat(szTopicParam, ",menubar=no");
  597.     }
  598.  
  599.     if (a_pWndOption->m_nStyle &RHWO_RESIZABLE) {
  600.         strcat(szTopicParam, ",resizable=yes");
  601.     }
  602.     else {
  603.         strcat(szTopicParam, ",resizable=no");
  604.     }
  605.  
  606.     if (a_pWndOption->m_nStyle &RHWO_TOOLBAR) {
  607.         strcat(szTopicParam, ",toolbar=yes");
  608.     }
  609.     else {
  610.         strcat(szTopicParam, ",toolbar=no");
  611.     }
  612.  
  613.     if (a_pWndOption->m_nStyle &RHWO_STATUS) {
  614.         strcat(szTopicParam, ",status=yes");
  615.     }
  616.     else {
  617.         strcat(szTopicParam, ",status=no");
  618.     }
  619.  
  620.     if (a_pWndOption->m_nStyle &RHWO_SCROLLBARS) {
  621.         strcat(szTopicParam, ",scrollbars=yes");
  622.     }
  623.     else {
  624.         strcat(szTopicParam, ",scrollbars=no");
  625.     }
  626.  
  627.     if (a_pWndOption->m_nTop >= 0)
  628.     {
  629.         sprintf(strTop, ",top=%d", a_pWndOption->m_nTop);
  630.         strcat(szTopicParam, strTop);
  631.         sprintf(strScreenY, ",screenY=%d", a_pWndOption->m_nTop);
  632.         strcat(szTopicParam, strScreenY);
  633.     }
  634.  
  635.     if (a_pWndOption->m_nLeft >= 0)
  636.     {
  637.         sprintf(strLeft, ",left=%d", a_pWndOption->m_nLeft);
  638.         strcat(szTopicParam, strLeft);
  639.         sprintf(strScreenX, ",screenX=%d", a_pWndOption->m_nLeft);
  640.         strcat(szTopicParam, strScreenX);
  641.     }
  642.  
  643.  
  644.     if (a_pWndOption->m_nHeight > 0)
  645.     {
  646.         sprintf(strHeight, ",height=%d", a_pWndOption->m_nHeight);
  647.         strcat(szTopicParam, strHeight);
  648.         sprintf(strOuterHeight, ",outerHeight=%d", a_pWndOption->m_nHeight);
  649.         strcat(szTopicParam, strOuterHeight);
  650.     }
  651.  
  652.     if (a_pWndOption->m_nWidth > 0)
  653.     {
  654.         sprintf(strWidth, ",width=%d", a_pWndOption->m_nWidth);
  655.         strcat(szTopicParam, strWidth);
  656.         sprintf(strOuterWidth, ",outerWidth=%d", a_pWndOption->m_nWidth);
  657.         strcat(szTopicParam, strOuterWidth);
  658.     }
  659.  
  660.     char szTotalUrl[_MAX_PATH + _MAX_PATH];
  661.     strcpy(szTotalUrl, a_pszUrl);
  662.     strcat(szTotalUrl, szTopicParam);
  663.     int len = strlen(szTempFileFormat) + strlen(szTotalUrl);
  664.     unsigned long wlen = 0;
  665.     char *pszFullBuffer = new char[len + 1];
  666.     sprintf(pszFullBuffer, szTempFileFormat, szTotalUrl);
  667.     WriteFile((HANDLE)hFile, pszFullBuffer, len, &wlen, NULL);
  668.     CloseHandle((HANDLE)hFile);
  669.     delete[] pszFullBuffer;
  670.  
  671.     //run shell execute to launch default browsre to view it
  672.     if ((int)ShellExecute(NULL, "opennew", szFile, NULL, NULL, SW_SHOWNORMAL) > 32)
  673.         return ShowHelpTopic_NonWin32(a_pszUrl);
  674.     
  675.     return 0;
  676. }
  677. #endif
  678.  
  679.